<template>
	<div class="login-container">
		<div class="login-intro">
			<h1>{{ $t('app.title') }}</h1>
			<div class="desc">
				{{ $t('app.description') }}
			</div>
			<div class="login-bg"><img src="@/assets/login.png" alt="" /></div>
		</div>
		<div class="login-form">
			<div class="login-title">
				<el-button link :class="loginType === 'account' ? 'account' : ''" @click="loginSwitch('account')">{{ $t('app.signIn') }}</el-button>
				<el-button link :class="loginType === 'company' ? 'account' : ''" @click="loginSwitch('company')">企业登录</el-button>
			</div>
			<account v-if="loginType === 'account'" />
			<!-- <mobile v-if="loginType === 'mobile'" /> -->
			<!-- <third /> -->
		</div>
	</div>
</template>

<script setup lang="ts">
import cache from '@/utils/cache'
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import Account from './account.vue'
import { Lock } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus/es'

const route = useRoute()
const router = useRouter()

const digitalSignatureOk = ref(true) // 是否通过数字证书登录
const loading = ref(false) // 加载状态;
const digital = ref({
	sign: ''
})
const digitalSignatureLogin = () => {
	if (digital.value.sign === '') {
		ElMessage.error('请输入数字证书密码')
		return
	}
	// 这里可以添加数字证书验证逻辑
	// 模拟验证通过
	loading.value = true
	setTimeout(() => {
		loading.value = false
		digitalSignatureOk.value = true
	}, 800)
}

// 登录类型
const loginType = ref('account')
const loginSwitch = (type: string) => {
	loginType.value = type
	if (type === 'company') {
		router.replace('/login/company')
	}
}

// 登录跳转
watch(
	() => route,
	value => {
		const redirect = route?.query?.redirect as string
		if (redirect && redirect !== '/') {
			cache.setRedirect(redirect)
		} else {
			cache.setRedirect('')
		}
	},
	{ immediate: true }
)
</script>

<style lang="scss" scoped>
.login-container {
	display: flex;
	justify-content: space-evenly;
	align-items: center;
	height: 100vh;
}

.login-intro {
	display: flex;
	flex-direction: column;
	width: 520px;
	flex: 0 1 auto;
}

.login-intro h1 {
	color: var(--el-color-primary);
}

.login-intro .desc {
	color: rgb(113, 115, 112);
	line-height: 32px;
	padding: 15px 0;
}

.login-bg img {
	width: 520px;
}

.login-title {
	display: flex;
	justify-content: space-around;
	margin-bottom: 20px;

	:deep(.el-button) {
		font-size: 20px;
		color: #333;
		padding-bottom: 8px;
	}

	.account {
		color: var(--el-color-primary);
		border-bottom: 4px solid var(--el-color-primary) !important;
	}
}

.login-form {
	background-color: #fff;
	flex: 0 1 auto;
	padding: 40px;
	border-radius: 6px;
	box-shadow: 1px 1px 8px #aaa6a6;
	box-sizing: border-box;
	width: 440px;

	:deep(.el-input) {
		height: 45px;
		margin-top: 5px;

		.el-input__inner {
			padding: 10px 15px 10px 5px;
			height: 45px;
			line-height: 45px;
			color: #666;
			font-size: 16px;
		}
	}
}

.digital-signature {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 1000px;
	display: flex;
	justify-content: space-between;
	padding: 50px;
	background: white;
	border: 2px solid #999;
	box-shadow: 0 0 20px #999;

	h3 {
		font-weight: bold;
		margin-bottom: 20px;
	}

	.signature-left {
		width: 450px;

		h3 {
			border-bottom: 2px solid #d2b77a;
			padding-bottom: 10px;
			display: inline-block;
		}

		.warm-reminder {
			color: red;
			font-size: 14px;
			margin: 15px 0;

			p {
				margin: 5px 0;
			}
		}

		.login-btn {
			width: 100%;
			height: 45px;
			font-size: 18px;
			margin-bottom: 20px;
		}

		.links {
			font-size: 14px;
			color: #666;

			div {
				display: flex;
				justify-content: space-between;
				margin-bottom: 10px;
			}
		}
	}

	.signature-right {
		width: 450px;

		h3 {
			color: #007bff;
		}

		ul {
			list-style: none;
			padding: 0;

			li {
				margin-bottom: 15px;

				a {
					text-decoration: none;
					color: #007bff;
					font-size: 16px;
				}
			}
		}
	}
}

@media only screen and (max-width: 992px) {
	.login-intro {
		display: none;
	}

	.digital-signature {
		position: static;
		transform: none;
		flex-direction: column;
		width: 100%;
		align-items: center;

		.signature-left,
		.signature-right {
			width: 90%;
			margin-bottom: 20px;
		}
	}
}

@media only screen and (max-width: 768px) {
	.login-container {
		background: #fff;
	}

	.login-intro {
		display: none;
	}

	.login-form {
		flex: 0 1 auto;
		border-radius: 0;
		box-shadow: none;
	}

	.login-captcha {
		:deep(.el-input) {
			width: 150px;
		}
	}
}
</style>
